package com.tbit.uqbike.webmanager.controller;

import com.tbit.uqbike.enums.SystemCodeEnum;
import com.tbit.uqbike.manager.exception.BaseException;
import com.tbit.uqbike.object.pojo.Geo;
import com.tbit.uqbike.object.value.WeatherResponse;
import com.tbit.uqbike.object.view.JsonResult;
import com.tbit.uqbike.service.base.GeoService;
import com.tbit.uqbike.service.business.WeatherService;
import com.tbit.uqbike.webmanager.util.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author jing
 * @date 2020/11/1713:47
 * @Description:天气
 */
@RestController
@RequestMapping("/weather")
public class WeatherController {
    @Autowired
    private WeatherService weatherService;
    @Autowired
    private GeoService geoService;

    /**
     * @param areaId
     * @return com.tbit.uqbike.object.view.JsonResult
     * @Description: 根据区域获取实况天气
     * @createDate 2020/11/17 14:20
     */
    @RequestMapping("/now")
    public JsonResult getNowWeather(Integer areaId) {
        Assert.notNull(areaId, "ver.accountId.notNull");
        Geo geo = geoService.getByAccountId(areaId);
        if (null == geo) {
            throw new BaseException(SystemCodeEnum.GEO_IS_NOT_NULL);
        }
        WeatherResponse.NowBean nowWeather = weatherService.getNowWeather(geo.getCenterLo(), geo.getCenterLa(), areaId);
        return JsonResult.ok(nowWeather);
    }
}
